<?php

function USER_detail($name){
	return SQL_select_one('admin',"name = '$name'");
}	

function USER_logout(){
	global $_username;
	setcookie("login", '', time()-3600);
	$_username = false;
}
	
function USER_register($name, $pass, $mail){
	if (USER_detail($name) <> null){
		return "Benutzername ist schon vorhanden";
	}
	
	SQL_insert('admin', array(
			'name' 	=> $name,
			'mail'	=> $mail,
			'pass'	=> md5($pass)
		)
	);
	
	USER_login($name, $pass);
	
	return false;	// Keine Fehler
}


function USER_list(){
	return SQL_select_as_array('admin');
}

function USER_update($name, $to){
	return SQL_update('admin', "name = '$name'", $to);	
}

function USER_server_list($name){
	return SQL_select_as_array('server_has_admin, server',"server_has_admin.name = '$name' AND server_has_admin.id = server.id");
}

